# Maintainer: Konstantin Podsvirov <konstantin@podsvirov.pro>

_realname=pelican
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=4.8.0
pkgrel=3
pkgdesc='A tool to generate a static blog, with restructured text (or markdown) input files (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://getpelican.com/'
license=('AGPL3')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-jinja"
         "${MINGW_PACKAGE_PREFIX}-python-pygments"
         "${MINGW_PACKAGE_PREFIX}-python-feedgenerator"
         "${MINGW_PACKAGE_PREFIX}-python-pytz"
         "${MINGW_PACKAGE_PREFIX}-python-docutils"
         "${MINGW_PACKAGE_PREFIX}-python-blinker"
         "${MINGW_PACKAGE_PREFIX}-python-unidecode"
         "${MINGW_PACKAGE_PREFIX}-python-six"
         "${MINGW_PACKAGE_PREFIX}-python-dateutil"
         "${MINGW_PACKAGE_PREFIX}-python-rich")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx_rtd_theme"
             "${MINGW_PACKAGE_PREFIX}-cc")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-nose")
optdepends=("${MINGW_PACKAGE_PREFIX}-python-markdown: Markdown support"
            "${MINGW_PACKAGE_PREFIX}-asciidoc: AsciiDoc support"
            "${MINGW_PACKAGE_PREFIX}-python-beautifulsoup4: importing from wordpress/dotclear/posterous"
            #"${MINGW_PACKAGE_PREFIX}-python-feedparser: importing from feeds"
            "${MINGW_PACKAGE_PREFIX}-python-rst2pdf: PDF generation"
            "openssh: uploading through SSH"
            "rsync: uploading through rsync+SSH"
            "lftp: uploading through FTP"
            #"s3cmd: uploading through S3"
            #"${MINGW_PACKAGE_PREFIX}-python-ghp-import: uploading through gh-pages"
            #"${MINGW_PACKAGE_PREFIX}-python-typogrify: typographical enhancements"
            #"${MINGW_PACKAGE_PREFIX}-pandoc: for pelican-import auto convert"
	          #"${MINGW_PACKAGE_PREFIX}-python-mdx-video: easier embedding of youtube videos in markdown"
           )
source=("pelican-${pkgver}.tar.gz"::"https://github.com/getpelican/pelican/archive/${pkgver}.tar.gz"
        https://github.com/getpelican/pelican/commit/33aca76d.patch
        https://github.com/getpelican/pelican/commit/3937028c.patch)
sha256sums=('e61e6a31abff4354477b211fdaeb14dd0d4df08e2d44a1c64f918f2c09c5e249'
            '56cf3a6912b67a0f8981f339fe7386053102d4ad57bf3b1a67e6a2031da9bdee'
            '50bb55dc51bc0460565e6c731b7792fffdd2284054342f496bf61fe58fede946')

prepare() {
  cd "pelican-${pkgver}"

  patch -p1 -i "${srcdir}/33aca76d.patch" # Fix build with sphinx 6
  patch -p1 -i "${srcdir}/3937028c.patch" # Fix tests with python 3.11

  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "pelican-${pkgver}" "python-build-${CARCH}"
}

build() {
  msg "Python build for ${CARCH}"
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build

  msg "Building documentation"
  cd "${srcdir}/python-build-${CARCH}/docs"
  PYTHONPATH="${srcdir}/python-build-${CARCH}/build/lib" \
    make man html
}

check() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONPATH="${srcdir}/python-build-${CARCH}/build/lib" \
    ${MINGW_PREFIX}/bin/nosetests
}

package() {
  cd "${srcdir}/python-build-${CARCH}"
  PYTHONUTF8=1 \
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" -O1 --skip-build

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done

  # documentation
  local _docdir="${srcdir}/python-build-${CARCH}/docs/_build"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/man/man1"
  for _ff in "${_docdir}/man/*.1"
  do
    cp ${_ff} "${pkgdir}${MINGW_PREFIX}/share/man/man1/"
  done
  mkdir -p "${pkgdir}${MINGW_PREFIX}/share/doc"
  cp -r "${_docdir}/html/" "${pkgdir}${MINGW_PREFIX}/share/doc/${_realname}"
  # license
  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}

# vim: ts=2 sw=2 et:
